class my_except(Exception): #异常大多继承exception,excepyion继承baseexception
    def __init__(self, msg):
        super().__init__()
        self.msg = msg
        
    def __str__(self):
        return self.msg
    
def name_input():
    name = input("请输入姓名：")
    name = name.strip() #去空格
    if name == "":
        raise my_except("不能为空") #eaise抛出一个异常
    elif len(name)>=4:
        raise my_except("名字过长")
    for ele in name:
        if ele.isdigit():
            raise my_except("不能包含数字")
    return name
while True:
    try:
        name = name_input()
        print(name)
    except my_except as e:
        print("自定义异常：",e)
    """
    多个异常捕获:except xxx:
            except(xxx,xxx) as b
            print(b) 
    """